import modelBody from "../aftersale/aftersale.vue"
import gridHeader from "@/components/print/selectTemplet.vue"
let extension = {
  components: {
    //查询界面扩展组件
    gridHeader,
    gridBody: '',
    gridFooter: '',
    //新建、编辑弹出框扩展组件
    modelHeader: "",
    modelBody: modelBody,
  },
  tableAction: '', //指定某张表的权限(这里填写表名,默认不用填写)
  buttons: { view: [], box: [], detail: [] }, //扩展的按钮
  methods: {
    //下面这些方法可以保留也可以删除
    async onInit() {
      this.queryFields = ["Client", "Finish_date"]
      let startTime = this.base.getOneWeekAgoDate()
      let endTime = this.base.getDate(false) + " 23:59:59"
      this.searchFormFields.Finish_date = [startTime, endTime]
      this.detailOptions.textInline = false
      this.textInline = false
      this.editFormOptions.forEach(x => {
        x.forEach(item => {
          if (item.field == 'Attachment' || item.field == 'Image') {
            item.multiple = true;
            item.maxFile = 10;
          }
        })
      })
      if (this.$route.path == "/q_aftersale_notarize" && JSON.stringify(this.$route.query) != '{}') {
        console.log("触发查询")
        await this.base.setSearchParamFn(this)
        // this.searchFormFields.Voucher_sub = null
        // this.searchFormFields.Voucher_sub_aftersale = null
        // this.searchFormFields.Client = null
        // this.searchFormFields.Proposer = null
        // this.searchFormFields.AuditStatus = null
        // this.searchFormFields.Finish_date = [null, null]
        // const selectList = ['Finish_date','AuditStatus','Client',]
        // this.searchFormOptions.forEach(item => {
        //   item.forEach(x => {
        //     if (selectList.includes(x.field)) {
        //       x.onChange = (v) => {
        //         this.$route.query = {}
        //       }
        //     }
        //   })
        // })
        setTimeout(() => {
          this.refresh()
        })
      }
    },
    async onInited() {
      // await this.setFiexdSearchForm(true);
      // await this.buttons.forEach(item => {
      //   if (item.name == "高级查询") {
      //     item.hidden = true
      //   }
      // })
      // this.editFormOptions.forEach(option => {
      //   option.forEach(item => {
      //     if (item.field == "Voucher_sub") {
      //       item.remote = true
      //       item.extra = {
      //         icon: "el-icon-zoom-in",
      //         text: "售后服务单",
      //         style: "color:#3a8ee6;font-size:13px;cursor:pointer;",
      //         click: () => {
      //           this.$refs.modelBody.open()
      //         }
      //       }
      //     }
      //   })
      // })
    },
    async searchBefore(param) {
      // console.log(this.searchFormOptions)
      //界面查询前,可以给param.wheres添加查询参数
      //返回false，则不会执行查询
      if (this.$route.path == "/q_aftersale_notarize" && JSON.stringify(this.$route.query) != '{}') {
        await this.base.setSearchBefore(this, "Aftersale_notarize",param)
        // const sectionState = ["[null,null]", JSON.stringify(["", null]), JSON.stringify([null, ""]), JSON.stringify(["", ""])]
        // const dateState = sectionState.includes(JSON.stringify(this.searchFormFields.Finish_date))
        // if (this.searchFormFields.Voucher_sub || this.searchFormFields.Voucher_sub_aftersale || this.searchFormFields.Proposer || !dateState) {
        //   param.wheres = param.wheres.filter(item => item.name != "Aftersale_notarize")
        //   this.$route.query = {}
        // }
      }
      return true;
    },
    searchAfter(result) {
      //查询后，result返回的查询数据,可以在显示到表格前处理表格的值
      return true;
    },
    delBefore(ids, rows) { //查询界面的表删除前 ids为删除的id数组,rows删除的行
      let auditStatus = rows.some(x => { return x.AuditStatus == 1 });
      if (auditStatus) {
        this.base.ElMessageFn('不支持删除审核通过数据')
        return false;
      }
      return true;
    },
    rowClick({ row, column, event }) {
      //查询界面点击行事件
      this.$refs.table.$refs.table.toggleRowSelection(row);
    },
    async modelOpenBefore(row) {
      this.CreateUserBoole = row.CreateID == this.$store.state.userID
      this.rowAuditStatus = await row.AuditStatus
      if (JSON.stringify(row) == "{}") {
        this.rowAuditStatus = 0
        this.CreateUserBoole = true
      }
      if (this.$route.path != "/q_aftersale_notarize" || this.rowAuditStatus != 0) {//|| !this.CreateUserBoole
        this.boxButtons[0].hidden = true
      } else {
        this.boxButtons[0].hidden = false
      }
    },
    modelOpenAfter(row) {
      if (this.currentAction == "Add") {
        this.editFormFields.Finish_date = this.base.getDate()
      }
      this.editFormOptions.forEach(item => {
        item.forEach(x => {
          if (x.field == "Aftersale_ID") {
            x.hidden = true
          }
          if (x.field != "Remark" && x.field != "Proposer" && x.field != "Finish_date" && x.field != "Image" && x.field != "Attachment") {
            x.disabled = true
          } else {
            x.disabled = false
          }
          if (this.$route.path != "/q_aftersale_notarize" || this.rowAuditStatus != 0) {//|| !this.CreateUserBoole
            x.disabled = true
            if (x.field == "Voucher_sub_aftersale") {
              x.extra = null
            }
          } else {
            if (x.field == "Voucher_sub_aftersale") {
              x.remote = true
              x.extra = {
                icon: "el-icon-zoom-in",
                text: "售后服务单",
                style: "color:#3a8ee6;font-size:13px;cursor:pointer;",
                click: () => {
                  this.$refs.modelBody.open()
                }
              }
            }
          }
        })
      })
    },

  }
};
export default extension;
